home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.015.CDev.Samples / Assembly / CDev.aii next >
Encoding:
Text File  |  1990-06-24  |  14.0 KB  |  468 lines  |  [TEXT/MPS ]

  1. ;############################################################
  2. ;#                                                            #
  3. ;#    File:            CDev.aii                                #
  4. ;#    Version:        3.0                                        #
  5. ;#    Author:                                                    #
  6. ;#    Copyright:        (c) 1989-1990 by Apple Computer, Inc.    #
  7. ;#    Developer Technical Support Apple II Sample Code        #
  8. ;#                                                            #
  9. ;#    Description:    This file contains the assembler needed    #
  10. ;#                    by the Shell CDEV on the IIGS.            #
  11. ;#                                                            #
  12. ;#----------------------------------------------------------#
  13. ;#                                                            #
  14. ;#    Development History:                                    #
  15. ;#                                                            #
  16. ;#    Who        Date        The Modification                    #
  17. ;#    ---        --------    ----------------                    #
  18. ;#                                                            #
  19. ;############################################################
  20.  
  21.             blanks    off
  22.             string    asis
  23.  
  24.             include    'E16.CDev'
  25.  
  26. ;############################################################
  27. ;#                                                            #
  28. ;#    CDEV executable module                                    #
  29. ;#                                                            #
  30. ;############################################################
  31.  
  32. ; This routine is eventually linked and then placed into a CDev code resource.  The only
  33. ; requirements are that this routine is at the beginning of the resource so if the CDev has
  34. ; any other routines they must follow this one.  The CDev's resource fork is always opened
  35. ; when a call to the CDev is made.  The CDev can also assume that the current port is set to
  36. ; the control panel window except in the boot message, where QuickDraw isn't even started,
  37. ; and in the About message, where it is the port of the help window.  All normal managers 
  38. ; will be started up for all calls except the boot call, which will only have miscTools and
  39. ; Resource Manager started.
  40.  
  41. CDEV        func
  42.  
  43.             import    CDEVLIST                        ;address of list of pointers to controls
  44.             import    AboutCDEV1                        ;pointer to about stuff
  45.  
  46. save_dbr    equ        $01
  47. retAddr        equ        $02
  48. data2        equ        $05
  49. data1        equ        $09
  50. message        equ        $0D
  51. retCode        equ        $0F
  52.  
  53.             phb                                        ;save DBR
  54.             tsc                                        ;get stack pointer
  55.             phd                                        ;save original direct page
  56.             tcd                                        ;make local direct page
  57.  
  58.             phk                                        ;set DBR to PBR
  59.             plb
  60.  
  61.             stz        retCode                            ;initialize return code
  62.             stz        retCode+2
  63.  
  64.             lda        message                            ;get message value
  65.             cmp        #RunCDEV+1                        ;valid message number?
  66.             bcc        good_message                    ;yes...
  67.             lda        #reserved1                        ;else put it in range
  68. good_message
  69.             dec        a                                ;fix for indexing
  70.             asl        a                                ;multiply by 2
  71.             tax                                        ;put into index register
  72.             lda        case_table,x                    ;get address of correct routine
  73.             pha                                        ;put on stack
  74.             rts                                        ;and do the 'rts' trick
  75.  
  76. case_table
  77.             dc.w    Machine_msg-1                    ;case MachineCDEV
  78.             dc.w    Boot_msg-1                        ;case BootCDEV
  79.             dc.w    ShutDown_msg-1                    ;case ShutDownCDEV
  80.             dc.w    Init_msg-1                        ;case InitCDEV
  81.             dc.w    Close_msg-1                        ;case CloseCDEV
  82.             dc.w    Events_msg-1                    ;case EventsCDEV
  83.             dc.w    Create_msg-1                    ;case CreateCDEV
  84.             dc.w    About_msg-1                        ;case AboutCDEV
  85.             dc.w    Rect_msg-1                        ;case RectCDEV
  86.             dc.w    Hit_msg-1                        ;case HitCDEV
  87.             dc.w    Run_msg-1                        ;case RunCDEV
  88.             dc.w    null_msg-1                        ;case reserved1 through NeverUsed2
  89.  
  90. ;----------------------------------------------------------------------------------------------------
  91. ; If the wantBoot flag is set, this routine will be called during the startup sequence.  The
  92. ; control panel takes care of drawing the "boot" icon.  When this call is made, the machine
  93. ; state is bad at best.  QuickDraw is not even started up.  The parameters to this call are
  94. ; undefined.
  95.  
  96. Boot_msg
  97.             bra        exit
  98.             
  99. ;----------------------------------------------------------------------------------------------------
  100. ; This is called if the wantMachine bit is set in the CDev flaags.  It enables the CDev to do
  101. ; further checking to see if it makes sense for the CDev to be visible to the user or not.
  102. ; For instance, if the CDev controls a setting for some hardware, we could check to see if
  103. ; the hardware is really connected.  The parameters are undefined for this call and the result
  104. ; is passed back as the function result.  0 = don't show this cdev, <>0 = show this CDev.
  105. ; The control panel will do some machine checking even before calling this routine by checking
  106. ; the ROM version number against the machine field of the CDev flags resource.
  107.  
  108. Machine_msg
  109.             bra        exit
  110.  
  111. ;----------------------------------------------------------------------------------------------------
  112. ; If the wantCreate bit is set, this message is called with the control panel's window ptr 
  113. ; passed in data1.  The cdev must create any controls it has during this call.  The CDEV's 
  114. ; resource fork is open during this call so resource manager calls can be made.  All controls
  115. ; rectangles MUST be relative to 0,0.  The control panel handles offsetting controls
  116. ; to the proper place in the window.  Initialization of the controls needs to be done in
  117. ; the InitCDEV call.  Just create the controls in this call.
  118.  
  119. Create_msg
  120.             jsr        do_Create                        ;go create the controls
  121.             bra        exit                            ;then return to caller
  122.  
  123. ;----------------------------------------------------------------------------------------------------
  124. ; If the wantInit flag is set, then this message is passed with data1 = the control panel's
  125. ; window ptr.  By  this time the CreateCDEV call will have been made and thus the controls
  126. ; used by the CDEV created.  This call enables the CDEV to initialize the controls before 
  127. ; they are displayed.
  128.  
  129. Init_msg
  130.             jsr        do_Init
  131.             bra        exit
  132.  
  133. ;----------------------------------------------------------------------------------------------------
  134. ; If the wantAbout bit is set in the CDEV flags, this call is made when the user selects help.
  135. ; Data1 = window ptr to the help window.  The control panel automatically handles the icon, 
  136. ; author, and version # display.
  137.  
  138. About_msg
  139.             jsr        do_About
  140.             bra        exit
  141.  
  142. ;----------------------------------------------------------------------------------------------------
  143. ; If a CDEV has a different size data rectangle depending on some state, like the printer & 
  144. ; modem port cdev's, then you can get a chance to tell the control panel this by setting the 
  145. ; wantRect bit in the CDEV flags.  In this call, data1 is a ptr to the rect and can be 
  146. ; directly modified by the CDEV.
  147.  
  148. Rect_msg
  149.             bra        exit
  150.  
  151. ;----------------------------------------------------------------------------------------------------
  152. ; If the wantEvents bit is set, the control panel will call this routine with data1 = ptr to
  153. ; the event record.  This allows the cdev to intercept and even *gasp* change the event record
  154. ; before it is handled by the control panel.
  155.  
  156. Events_msg
  157.             bra        exit
  158.  
  159. ;----------------------------------------------------------------------------------------------------
  160. ; If the CDEV wants to know when a control has been "hit", it can set the wantHit bit in the
  161. ; CDEV flags.  When called, data1 = Hdl to Ctl Hit & data2 = Ctl ID of hit control.  This message
  162. ; allows the CDEV to perform actions based on the control that was selected by the user.
  163.  
  164. Hit_msg
  165.             jsr        do_Hit
  166.             bra        exit
  167.  
  168. ;----------------------------------------------------------------------------------------------------
  169. ; This message is called if the "wantRun" bit is set in the CDEV flags.  It enables CDEVs like
  170. ; time to update the display.  It is called every 60th of a second - every time the DARun call
  171. ; is issued to the control panel. -no parameters are passed to this routine.
  172.  
  173. Run_msg
  174.             bra        exit
  175.  
  176. ;----------------------------------------------------------------------------------------------------
  177. ; The CloseCDEV message is passed if the wantClose bit is set in the CDEV flags and the control
  178. ; panel is closing or when the user selects another CDEV.  During  this call data1 = windowPtr.
  179. ; In general, CDEVs can do any memory disposal and saving of settings during this call.  The
  180. ; disposal of the CDEV's controls is handled automatically by the Control Panel.
  181.  
  182. Close_msg
  183.             bra        exit
  184.  
  185. ;----------------------------------------------------------------------------------------------------
  186. ; If the wantShutDown bit is set in the CDEV flags resource then this routine is called when
  187. ; the user either disables the CDEV or *someday* when the machine is being turned off.  It
  188. ; gives the CDEV a chance to turn itself off (or any hardware or software it controls).
  189. ; The parameters are undefined in this call.
  190.  
  191. ShutDown_msg
  192.             bra        exit
  193.  
  194. ;----------------------------------------------------------------------------------------------------
  195. ; This label is here to handle any message values that are out of range.
  196.  
  197. null_msg
  198.  
  199. ;----------------------------------------------------------------------------------------------------
  200.  
  201. exit
  202.             lda        save_dbr                        ;get saved DBR and low byte of return address
  203.             sta        data1+2                            ;move up in stack frame
  204.             lda        retAddr+1                        ;get high word of return address
  205.             sta        message                            ;move it up too
  206.             pld                                        ;restore original direct page
  207.             tsc                                        ;remove parms from stack
  208.             clc
  209.             adc        #10
  210.             tcs
  211.             plb                                        ;restore original DBR
  212.             rtl                                        ;and return to control panel shell
  213.  
  214. ;****************************************************************************************************
  215. ; do_Create - creates the popup controls
  216.  
  217. do_Create
  218.             pha                                        ;make room on stack for returned control handle
  219.             pha
  220.             pei        data1+2                            ;put window pointer on stack
  221.             pei        data1
  222.             pea        3                                ;referenceDesc = pointer to list of pointers
  223.             pea        CDEVLIST>>16                    ;put address of pointer on stack
  224.             pea        CDEVLIST
  225.             ldx        #$3110                            ;NewControl2 call
  226.             jsl        $e10000
  227.             pla                                        ;remove returned handle
  228.             pla
  229.             rts
  230.  
  231. ;****************************************************************************************************
  232. ; do_Init - sets the initial values of the popup controls
  233.  
  234. do_Init
  235.             pea        1                                ;put current value of control on stack (for SetCtlValue)
  236.  
  237.             pha                                        ;space for returned result
  238.             pha
  239.             pei        data1+2                            ;put window pointer on stack
  240.             pei        data1
  241.             pea        0
  242.             pea        1                                ;control ID
  243.             ldx        #$3010                            ;GetCtlHandleFromID call
  244.             jsl        $e10000
  245.  
  246.             ldx        #$1910                            ;SetCtlValue call
  247.             jsl        $e10000
  248.  
  249.             pea        1                                ;put current value of control on stack (for SetCtlValue)
  250.  
  251.             pha                                        ;space for returned result
  252.             pha
  253.             pei        data1+2                            ;put window pointer on stack
  254.             pei        data1
  255.             pea        0
  256.             pea        2                                ;control ID
  257.             ldx        #$3010                            ;GetCtlHandleFromID call
  258.             jsl        $e10000
  259.  
  260.             ldx        #$1910                            ;SetCtlValue call
  261.             jsl        $e10000
  262.  
  263.             pea        1                                ;put current value of control on stack (for SetCtlValue)
  264.  
  265.             pha                                        ;space for returned result
  266.             pha
  267.             pei        data1+2                            ;put window pointer on stack
  268.             pei        data1
  269.             pea        0
  270.             pea        3                                ;control ID
  271.             ldx        #$3010                            ;GetCtlHandleFromID call
  272.             jsl        $e10000
  273.  
  274.             ldx        #$1910                            ;SetCtlValue call
  275.             jsl        $e10000
  276.  
  277.             rts
  278.  
  279. ;****************************************************************************************************
  280. ; do_About - creates the About static text control
  281.  
  282. do_About
  283.             pha                                        ;space for returned handle
  284.             pha
  285.             pei        data1+2                            ;put window pointer on stack
  286.             pei        data1
  287.             pea        0                                ;referenceDesc = pointer to single control
  288.             pea        ABOUTCDEV1>>16                    ;put pointer to about stuff on stack
  289.             pea        ABOUTCDEV1
  290.             ldx        #$3110                            ;NewControl2 call
  291.             jsl        $e10000
  292.             pla                                        ;remove returned handle
  293.             pla
  294.             rts
  295.  
  296. ;****************************************************************************************************
  297. ; do_Hit - handles a control 'hit'
  298.  
  299. do_Hit
  300.             lda        data2                            ;get Control ID
  301.             cmp        #3                                ;is it three?
  302.             bcc        @not_three                        ;no...
  303.             pha                                        ;else save value
  304.             ldx        #$2c03                            ;SysBeep call
  305.             jsl        $e10000
  306.             pla                                        ;retrieve ctl id
  307. @not_three
  308.             cmp        #2                                ;two?
  309.             bcc        @not_two
  310.             pha                                        ;save value
  311.             ldx        #$2c03                            ;SysBeep
  312.             jsl        $e10000
  313.             pla
  314. @not_two
  315.             cmp        #1                                ;one?
  316.             bcc        @not_one
  317.             ldx        #$2c03
  318.             jsl        $e10000
  319. @not_one
  320.             rts
  321.  
  322.             endf
  323.  
  324. ;############################################################
  325. ;#                                                            #
  326. ;#    CDEV Control #1                                            #
  327. ;#                                                            #
  328. ;############################################################
  329.  
  330. CDEV1        proc
  331.  
  332.             dc.w    9
  333.             dc.l    1
  334.             dc.w    2,5,14,195
  335.             dc.l    $87000000
  336.             dc.w    $0040
  337.             dc.w    $1004
  338.             dc.l    0
  339.             dc.w    76
  340.             dc.l    CDEV1Menu
  341.             dc.w    1
  342.  
  343. CDEV1Menu
  344.             dc.b    '>> Item 1:\H'
  345.             dc.w    1
  346.             dc.b    $0d
  347.             dc.b    '== Impressive!\H'
  348.             dc.w    1
  349.             dc.b    $0d
  350.             dc.b    '== Elegant!\H'
  351.             dc.w    2
  352.             dc.b    $0d
  353.             dc.b    '== Amazing!\H'
  354.             dc.w    3
  355.             dc.b    $0d
  356.             dc.b    '== Stupendous!\H'
  357.             dc.w    4
  358.             dc.b    $0d
  359.             dc.b    '.'
  360.             endp
  361.  
  362. ;############################################################
  363. ;#                                                            #
  364. ;#    CDEV Control #2                                            #
  365. ;#                                                            #
  366. ;############################################################
  367.  
  368. CDEV2        proc
  369.             dc.w    9
  370.             dc.l    2
  371.             dc.w    17,5,29,195
  372.             dc.l    $87000000
  373.             dc.w    $0040
  374.             dc.w    $1004
  375.             dc.l    0
  376.             dc.w    80
  377.             dc.l    CDEV2Menu
  378.             dc.w    1
  379.  
  380. CDEV2Menu
  381.             dc.b    '>> Item 2:\H'
  382.             dc.w    2
  383.             dc.b    $0d
  384.             dc.b    '== Wow!\H'
  385.             dc.w    1
  386.             dc.b    $0d
  387.             dc.b    '== Golly!\H'
  388.             dc.w    2
  389.             dc.b    $0d
  390.             dc.b    '== Holy Cow!\H'
  391.             dc.w    3
  392.             dc.b    $0d
  393.             dc.b    '.'
  394.             endp
  395.  
  396. ;############################################################
  397. ;#                                                            #
  398. ;#    CDEV Control #3                                            #
  399. ;#                                                            #
  400. ;############################################################
  401.  
  402. CDEV3        proc
  403.             dc.w    9
  404.             dc.l    3
  405.             dc.w    32,5,44,195
  406.             dc.l    $87000000
  407.             dc.w    $0040
  408.             dc.w    $1004
  409.             dc.l    0
  410.             dc.w    80
  411.             dc.l    CDEV3Menu
  412.             dc.w    1
  413.  
  414. CDEV3Menu
  415.             dc.b    '>> Item 3:\H'
  416.             dc.w    3
  417.             dc.b    13
  418.             dc.b    '== Too Hip!\H'
  419.             dc.w    1
  420.             dc.b    13
  421.             dc.b    '== That''s All!\H'
  422.             dc.w    2
  423.             dc.b    13
  424.             dc.b    '.'
  425.             endp
  426.  
  427. ;############################################################
  428. ;#                                                            #
  429. ;#    CDEV Control Lists                                        #
  430. ;#                                                            #
  431. ;############################################################
  432.  
  433. CDEVLIST    proc
  434.  
  435.             dc.l    CDEV1
  436.             dc.l    CDEV2
  437.             dc.l    CDEV3
  438.             dc.l        0
  439.  
  440.             endp
  441.  
  442. ;############################################################
  443. ;#                                                            #
  444. ;#    CDEV 'About' control                                    #
  445. ;#                                                            #
  446. ;############################################################
  447.  
  448. AboutCDEV1    proc
  449.  
  450.             dc.w    8
  451.             dc.l    1
  452.             dc.w    38,5,138,280
  453.             dc.l    $81000000
  454.             dc.w    $0000
  455.             dc.w    $1000
  456.             dc.l    0
  457.             dc.l    theText
  458.             dc.w    endText-theText
  459.             
  460.             string    asis
  461. theText
  462.             dc.b    'This CDEV shows how easy it is to create a CDEV on the AppleIIgs.'
  463. endText
  464.             string    pascal
  465.  
  466.             endp
  467.  
  468.             end